package com.ljkj.cordial.chat.presenter;

import com.lanjiu.lib.communication.IMSConfig;
import com.lanjiu.lib.imclient.bus.MessageEvent;
import com.lanjiu.lib.imclient.ims.IMSContacts;
import com.lanjiu.lib.imclient.ims.read.IMSMessageReader;
import com.lanjiu.pro.business.BusinessProtocolMessageStandard;
import com.ljkj.cordial.lengthtcpheartbeat.OnShortResponseListener;

public abstract class OnEventShortResponseListener implements OnShortResponseListener {
    private IMSMessageReader reader;

    public OnEventShortResponseListener() {
        reader = new IMSMessageReader();
    }

    @Override
    public void onResponse(String msgType, BusinessProtocolMessageStandard.CheckUnifiedEntranceMessage msg) {
        BusinessProtocolMessageStandard.Head head = msg.getUnifiedEntranceMessage().getHead();
        BusinessProtocolMessageStandard.UnifiedEntranceMessage message = msg.getUnifiedEntranceMessage();
        int responseCode = IMSConfig.STATUS_REPORT_SUCCESS.equals(head.getStatusReport()) ? IMSContacts.ResponseCode.SUCCESS : IMSContacts.ResponseCode.FAILURE;
        MessageEvent event = reader.getRead(responseCode, head.getMsgType(), message, null);
        onEvent(event);
    }

    public abstract void onEvent(MessageEvent event);
}
